package com.arceus.leetcode.pat;

import java.util.Scanner;

/**
 * @author : iron
 * @version : 1.0.0
 * @date : 下午2:16 2018/9/11
 */

public class Main {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        for (int i = 0; i < num; i++) {
            String a = in.next();
            System.out.println(judge(a));
        }
    }

    private static String judge(String a) {
        if (a.indexOf("PAT") == -1) {
            if (a.indexOf("PT") == -1) {
                if (a.indexOf("PAAT") == -1) {
                    return "NO";
                }
            }
        }
        char[] arr = a.toCharArray();
        for (char c : arr) {
            if ('P' == c || 'A' == c || 'T' == c) {
                continue;
            }
            return "NO";
        }
        return "YES";
    }

}
